<?php
/**
 * @annotate 登陆类
 * @group   Admin/company
 * @author   mengke.yue <mengke.yue@gmail.com>
 */
class LoginAction extends BaseAction {
	public function sign_in(){
		$this->assign('Title',"人才来了后台登陆");
		$url=U('Company/index');
   	    $this->checkPost();
        $Admin = D('Company');
		$uname = getRequest('uname');
        $password = getRequest('password');
        $oUser=$Admin->getUser($uname);
      	if (empty($oUser)) {
			$this->Yes = "-1";
	        $this->Err = "对不起，用户名不存在！";
			//return false;
		}else{
			if ($oUser['company_pwd'] != md5(md5($password).$oUser['company_salt'])) {
			$this->Yes = "-1";
	        $this->Err = "对不起，密码不正确！";
			//return false;
			}else{
				$menu = D('company_menu')->where(array('cid'=>$oUser['cid']))->find();
				if($menu['mid'] == 2){
					$time = strtotime('+1 month',$menu['ctime']);
				}else if($menu['mid'] == 4){
					$time = strtotime('+3 month',$menu['ctime']);
				}else if($menu['mid'] == 5){
					$time = strtotime('+1 year',$menu['ctime']);
				}
				$now = time();
				if($now > $time){
					$this->Yes = "-1";
	        		$this->Err = "对不起，您的套餐已经到期，如需继续使用，请您续费，或者联系我们！";
				}else{
					$Admin->add_logintime($oUser['cid']);
					$pic = D('company_info')->where(array('cid'=>$oUser['cid'],'is_del'=>0))->find();
					$pic = get_img_url($pic['logo']);
					$oUser['url'] = $pic['url'];
					$_SESSION['company'] = $oUser;
					$this->setcookie();
					//$this->assign("jumpUrl",$url);//跳转
					$this->Yes = 1;
			        $this->Suce = "登陆成功！";
			        $this->Jurl = $url;
			        //$this->success("登陆成功！");	
				}
				
			}
		}
		  
		
		$this->display();
	}
	
	public function setcookie(){
		$cid = authcode($_SESSION['company']['cid'],'ENCODE');
		$tomorow = strtotime(date('Ymd',time()))+3600*24;
		cookie('rccid',$cid,$tomorow-time());
	}

	public function sign_out(){
		$url=U('Login/sign_in');
		unset($_SESSION['company']);
		cookie('rccid',null);
		$this->assign("jumpUrl",$url);//跳转
		$this->success("退出成功！");		
	}
}
?>